pid-port
Get the ID of the process that uses a certain port
Install
$ npm install pid-port
Usage
const pidPort = require('pid-port');
(async () => {
try {
console.log(await pidPort.portToPid(8080));
const pids = await pidPort.portToPid([8080, 22]);
console.log(pids.get(8080));
console.log(pids.get(22));
} catch (error) {
console.log(error);
}
})();
API
pidPort.portToPid(port)
Returns a Promise<number>
with the process ID.
port
Type: number
Port to look up.
pidPort.portToPid(ports)
Returns a Promise<Map<number, number>>
with the port as key and the process ID as value.
ports
Type: number[]
Ports to look up.
pidPort.all()
Get all process IDs from ports.
Returns a Promise<Map<number, number>>
with the port as key and the process ID as value.